
#https://www.hxzq.cn/index.php?id=rzrq&cate=ywgg
#https://www.hxzq.cn/index.php?id=rzrq&cate=ywgg&pageid=2
#https://www.hxzq.cn/index.php?id=rzrq&cate=ywgg&pageid=3
import requests
from bs4 import BeautifulSoup

headers={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70',
    'Referer': 'https://www.hxzq.cn/index.php?id=rzrq&cate=ywgg&pageid=2',
    'Cookie': 'PHPSESSION=2mgco9di44g6d0rc4sv3ac2rp6'
}
Session=requests.session()
Session.headers=headers

def tableGet(url):
    html=Session.get(url)
    soup = BeautifulSoup(html.text, 'lxml')
    lines=soup.select('.read-content table tbody tr')
    for line in lines:
        tds=line.select('td')
        for td in tds:
            print(td.text.replace(' ','').replace('\n',''),end=' ')
        print('')

def getIndex():
    for i in range(1,3):
        url = f'https://www.hxzq.cn/index.php?id=rzrq&cate=ywgg&pageid={i}'
        print(f'正在处理第{i}页')
        html=Session.get(url)
        soup=BeautifulSoup(html.text,'lxml')
        items=soup.select('.items .item.fc')
        for item in items:
            item_list=item.select_one('a')
            title=item_list.text
            href=item_list['href']
            if '证券调整公告' in title:
                print(title,href)
                tableGet(href)

if __name__ == '__main__':
    getIndex()